<?php
define('SSv2_SAMPLE_DIR', 'D:\\sitestar3.1_install_file\\installation_sample\\sample_data');
$tpl_scalar = $_GET['tpl_scalar'];
$level = $_GET['level'];

$result = 'ERROR';
    $tables_to_be_reset = array(
        'es_article_categories', 'es_articles', 'es_download_categories', 'es_downloads', 
        'es_friendlinks', 'es_galleries', 'es_menu_items', 'es_menus', 'es_module_blocks', 
        'es_navigations', 'es_online_qqs', 'es_product_categories', 'es_products', 'es_static_contents', 
        'es_templates');
    $sample_data_file = SSv2_SAMPLE_DIR.'/'.$tpl_scalar.'_sample_'.$level.'.sql';die($sample_data_file);
    if (!file_exists($sample_data_file)) {
        $sample_data_file = SSv2_SAMPLE_DIR.'/sample.sql';
    }
    if (file_exists($sample_data_file)) {
        $fp_sample = fopen($sample_data_file, 'r');
        
        $full_sql = '';
        while (!feof($fp_sample)) {
            $line = fgets($fp_sample);
            if (preg_match('/^\-\-/', $line) 
                || preg_match('/^\/\*/', $line) 
                || preg_match('/^LOCK/', $line) 
                || preg_match('/^UNLOCK/', $line)) continue;
            $full_sql .= $line;
        }
        
        fclose($fp_sample);
        
        $tmp_sqls = preg_split('/(;\r\n)|(;\n)/s', $full_sql);
        $table_name_match = array();
        $result = array();
        foreach ($tmp_sqls as $sql) {
            if (strlen(trim($sql)) == 0) continue;
            preg_match('/`([^`]+)`/', $sql, $table_name_match);
            if (in_array($table_name_match[1], $tables_to_be_reset)) {
                $result[] = $sql;
            }
        }
    }
    
    return serialize($result);

?>